const express = require("express");
const router = express.Router();
const userHandler = require("../router_handler/user_handler");

/**
 * @openapi
 * /myApi/login:
 *   post:
 *     summary: 用户登录接口
 *     description: 用户使用账号和密码进行登录操作
 *     tags:
 *       - 用户认证
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               userNumber:
 *                 type: string
 *                 description: 用户账号
 *               passWord:
 *                 type: string
 *                 description: 用户密码
 *     responses:
 *       200:
 *         description: 登录成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: number
 *                   description: 状态码，200 表示成功
 *                 token:
 *                   type: string
 *                   description: 用户的 token
 *                 message:
 *                   type: string
 *                   description: 响应信息
 *       404:
 *         description: 账号不存在
 *       401:
 *         description: 密码错误
 */
router.post("/login", userHandler.login_handler);

/**
 * @openapi
 * /myApi/getUserinfo:
 *   get:
 *     summary: 获取用户信息接口
 *     description: 根据用户的 token 获取用户的详细信息
 *     tags:
 *       - 用户认证
 *     parameters:
 *       - in: header
 *         name: token
 *         schema:
 *           type: string
 *         required: true
 *         description: 用户的 token
 *     responses:
 *       200:
 *         description: 获取成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: number
 *                   description: 状态码，200 表示成功
 *                 data:
 *                   type: object
 *                   properties:
 *                     userName:
 *                       type: string
 *                       description: 用户姓名
 *                     avatar:
 *                       type: string
 *                       description: 用户头像链接
 *                     routes:
 *                       type: array
 *                       items:
 *                         type: string
 *                       description: 用户的路由权限
 *                     userId:
 *                       type: string
 *                       description: 用户 ID
 *       401:
 *         description: 用户已注销或 TOKEN 已过期
 */
router.get("/getUserinfo", userHandler.getUserinfo_handler);

/**
 * @openapi
 * /myApi/getBrandData/{currentPage}/{pageSize}:
 *   get:
 *     summary: 获取品牌数据接口
 *     description: 根据分页信息获取品牌数据
 *     tags:
 *       - 品牌管理
 *     parameters:
 *       - in: path
 *         name: currentPage
 *         schema:
 *           type: number
 *         required: true
 *         description: 当前页码
 *       - in: path
 *         name: pageSize
 *         schema:
 *           type: number
 *         required: true
 *         description: 每页显示的记录数
 *     responses:
 *       200:
 *         description: 获取成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: number
 *                   description: 状态码，200 表示成功
 *                 data:
 *                   type: object
 *                   properties:
 *                     tableData:
 *                       type: array
 *                       items:
 *                         type: object
 *                       description: 分页后的品牌数据
 *                     total:
 *                       type: number
 *                       description: 品牌数据的总数
 */
router.get("/getBrandData/:currentPage/:pageSize", userHandler.getBrandData_handler);

/**
 * @openapi
 * /myApi/uploadImg:
 *   post:
 *     summary: 上传品牌图片接口
 *     description: 上传品牌图片并可关联品牌信息
 *     tags:
 *       - 品牌管理
 *     parameters:
 *       - in: header
 *         name: token
 *         schema:
 *           type: string
 *         required: true
 *         description: 用户的 token
 *     requestBody:
 *       required: true
 *       content:
 *         multipart/form-data:
 *           schema:
 *             type: object
 *             properties:
 *               brandId:
 *                 type: string
 *                 description: 品牌 ID（可选）
 *               brandName:
 *                 type: string
 *                 description: 品牌名称
 *               file:
 *                 type: string
 *                 format: binary
 *                 description: 品牌图片文件
 *     responses:
 *       200:
 *         description: 上传成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: number
 *                   description: 状态码，200 表示成功
 *                 message:
 *                   type: string
 *                   description: 响应信息
 *       500:
 *         description: 上传失败
 */
router.post("/uploadImg", userHandler.uploadImg_handler);

/**
 * @openapi
 * /myApi/getAclUserData:
 *   get:
 *     summary: 获取用户列表接口
 *     description: 获取用户管理相关的用户列表
 *     tags:
 *       - 用户管理
 *     parameters:
 *       - in: header
 *         name: token
 *         schema:
 *           type: string
 *         required: true
 *         description: 用户的 token
 *     responses:
 *       200:
 *         description: 获取成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: number
 *                   description: 状态码，200 表示成功
 *                 data:
 *                   type: object
 *                   properties:
 *                     userData:
 *                       type: array
 *                       items:
 *                         type: object
 *                       description: 用户列表
 */
router.get("/getAclUserData", userHandler.getAclUserData_handler);

/**
 * @openapi
 * /myApi/createUserData:
 *   post:
 *     summary: 创建用户接口
 *     description: 创建新的用户信息
 *     tags:
 *       - 用户管理
 *     parameters:
 *       - in: header
 *         name: token
 *         schema:
 *           type: string
 *         required: true
 *         description: 用户的 token
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               userData:
 *                 type: object
 *                 properties:
 *                   userNumber:
 *                     type: string
 *                     description: 用户账号
 *                   userName:
 *                     type: string
 *                     description: 用户姓名
 *                   userSex:
 *                     type: string
 *                     description: 用户性别
 *                   userPhone:
 *                     type: string
 *                     description: 用户电话
 *                   userRole:
 *                     type: string
 *                     description: 用户角色
 *                   date:
 *                     type: string
 *                     description: 用户创建日期
 *                   state:
 *                     type: boolean
 *                     description: 用户状态
 *                   Email:
 *                     type: string
 *                     description: 用户邮箱
 *                   section:
 *                     type: string
 *                     description: 用户所在部门
 *                   brief:
 *                     type: string
 *                     description: 用户简介
 *                   passWord:
 *                     type: string
 *                     description: 用户密码
 *     responses:
 *       200:
 *         description: 创建成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: number
 *                   description: 状态码，200 表示成功
 *                 message:
 *                   type: string
 *                   description: 响应信息
 *       400:
 *         description: 用户账号不能相同
 */
router.post("/createUserData", userHandler.createUserData_handler);

/**
 * @openapi
 * /myApi/editUserData:
 *   post:
 *     summary: 编辑用户接口
 *     description: 根据用户 ID 编辑用户信息
 *     tags:
 *       - 用户管理
 *     parameters:
 *       - in: header
 *         name: token
 *         schema:
 *           type: string
 *         required: true
 *         description: 用户的 token
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               userData:
 *                 type: object
 *                 properties:
 *                   id:
 *                     type: string
 *                     description: 用户 ID
 *                   # 其他用户信息字段
 *     responses:
 *       200:
 *         description: 编辑成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: number
 *                   description: 状态码，200 表示成功
 *                 message:
 *                   type: string
 *                   description: 响应信息
 *       404:
 *         description: 用户不存在
 */
router.post("/editUserData", userHandler.editUserData_handler);

/**
 * @openapi
 * /myApi/delUserData:
 *   post:
 *     summary: 删除用户接口
 *     description: 根据用户 ID 数组批量删除用户信息
 *     tags:
 *       - 用户管理
 *     parameters:
 *       - in: header
 *         name: token
 *         schema:
 *           type: string
 *         required: true
 *         description: 用户的 token
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               idArr:
 *                 type: array
 *                 items:
 *                   type: string
 *                 description: 需要删除的用户 ID 数组
 *     responses:
 *       200:
 *         description: 删除成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: number
 *                   description: 状态码，200 表示成功
 *                 message:
 *                   type: string
 *                   description: 响应信息
 */
router.post("/delUserData", userHandler.delUserData_handler);

/**
 * @openapi
 * /myApi/changeState:
 *   post:
 *     summary: 更改用户状态接口
 *     description: 根据用户的 token 更改用户的状态
 *     tags:
 *       - 用户管理
 *     parameters:
 *       - in: header
 *         name: token
 *         schema:
 *           type: string
 *         required: true
 *         description: 用户的 token
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               state:
 *                 type: boolean
 *                 description: 用户的新状态
 *     responses:
 *       200:
 *         description: 状态更新成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: number
 *                   description: 状态码，200 表示成功
 *                 message:
 *                   type: string
 *                   description: 响应信息
 *       404:
 *         description: 用户不存在
 */
router.post("/changeState", userHandler.changeState_handler);

/**
 * @openapi
 * /myApi/getAsyncRoute:
 *   get:
 *     summary: 获取异步路由配置接口
 *     description: 根据用户的 token 获取异步路由配置
 *     tags:
 *       - 权限管理
 *     parameters:
 *       - in: header
 *         name: token
 *         schema:
 *           type: string
 *         required: true
 *         description: 用户的 token
 *     responses:
 *       200:
 *         description: 获取成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: number
 *                   description: 状态码，200 表示成功
 *                 data:
 *                   type: object
 *                   properties:
 *                     asyncRoutes:
 *                       type: array
 *                       items:
 *                         type: object
 *                       description: 异步路由配置列表
 */
router.get("/getAsyncRoute", userHandler.getAsyncRoute_handler);

/**
 * @openapi
 * /myApi/distribute:
 *   post:
 *     summary: 分配用户权限接口
 *     description: 根据用户的 token 分配新的路由权限
 *     tags:
 *       - 权限管理
 *     parameters:
 *       - in: header
 *         name: token
 *         schema:
 *           type: string
 *         required: true
 *         description: 用户的 token
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               userToken:
 *                 type: string
 *                 description: 用户的 token
 *               routes:
 *                 type: array
 *                 items:
 *                   type: string
 *                 description: 用户的新路由权限
 *     responses:
 *       200:
 *         description: 权限分配成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: number
 *                   description: 状态码，200 表示成功
 *                 message:
 *                   type: string
 *                   description: 响应信息
 */
router.post("/distribute", userHandler.distribute_handler);

/**
 * @openapi
 * /myApi/getMessage:
 *   get:
 *     summary: 获取系统消息接口
 *     description: 根据用户的 token 获取系统消息列表
 *     tags:
 *       - 消息看板
 *     parameters:
 *       - in: header
 *         name: token
 *         schema:
 *           type: string
 *         required: true
 *         description: 用户的 token
 *     responses:
 *       200:
 *         description: 获取成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: number
 *                   description: 状态码，200 表示成功
 *                 data:
 *                   type: object
 *                   properties:
 *                     messageData:
 *                       type: array
 *                       items:
 *                         type: object
 *                       description: 系统消息列表
 */
router.get("/getMessage", userHandler.getMessage_handler);

/**
 * @openapi
 * /myApi/addMessage:
 *   post:
 *     summary: 添加系统消息接口
 *     description: 添加新的系统消息
 *     tags:
 *       - 消息看板
 *     parameters:
 *       - in: header
 *         name: token
 *         schema:
 *           type: string
 *         required: true
 *         description: 用户的 token
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               // 系统消息内容字段
 *     responses:
 *       200:
 *         description: 留言成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: number
 *                   description: 状态码，200 表示成功
 *                 message:
 *                   type: string
 *                   description: 响应信息
 */
router.post("/addMessage", userHandler.addMessage_handler);

/**
 * @openapi
 * /myApi/addBrandData:
 *   post:
 *     summary: 添加品牌数据接口
 *     description: 用于添加新的品牌数据
 *     tags:
 *       - 品牌管理
 *     parameters:
 *       - in: header
 *         name: token
 *         schema:
 *           type: string
 *         required: true
 *         description: 用户的 token
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               brandName:
 *                 type: string
 *                 description: 品牌名称
 *               brandDescription:
 *                 type: string
 *                 description: 品牌描述
 *               # 可以根据实际需求添加更多品牌相关的字段
 *     responses:
 *       200:
 *         description: 添加成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: number
 *                   description: 状态码，200 表示成功
 *                 message:
 *                   type: string
 *                   description: 响应信息
 *       400:
 *         description: 输入参数有误
 *       401:
 *         description: 用户认证失败
 */
router.post("/addBrandData", userHandler.addBrandData_handler);

/**
 * @openapi
 * /myApi/updateBrandData:
 *   post:
 *     summary: 修改品牌数据接口
 *     description: 根据品牌 ID 修改品牌的名称和 logo 地址
 *     tags:
 *       - 品牌管理
 *     parameters:
 *       - in: header
 *         name: token
 *         schema:
 *           type: string
 *         required: true
 *         description: 用户的 token
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               id:
 *                 type: string
 *                 description: 品牌 ID
 *               tmName:
 *                 type: string
 *                 description: 品牌名称
 *               logoUrl:
 *                 type: string
 *                 description: 品牌 logo 地址
 *     responses:
 *       200:
 *         description: 修改成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: number
 *                   description: 状态码，200 表示成功
 *                 message:
 *                   type: string
 *                   description: 响应信息
 *                 updatedBrand:
 *                   type: object
 *                   description: 更新后的品牌数据
 *       404:
 *         description: 未找到该品牌数据
 *       500:
 *         description: 修改品牌数据失败
 */
router.post("/updateBrandData", userHandler.updateBrandData_handler);

/**
 * @openapi
 * /myApi/deleteBrand/{id}:
 *   delete:
 *     summary: 删除品牌接口
 *     description: 根据品牌 ID 删除品牌数据
 *     tags:
 *       - 品牌管理
 *     parameters:
 *       - in: path
 *         name: id
 *         schema:
 *           type: string
 *         required: true
 *         description: 要删除的品牌 ID
 *       - in: header
 *         name: token
 *         schema:
 *           type: string
 *         required: true
 *         description: 用户的 token
 *     responses:
 *       200:
 *         description: 删除成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: number
 *                   description: 状态码，200 表示成功
 *                 message:
 *                   type: string
 *                   description: 响应信息
 *                 deletedBrand:
 *                   type: object
 *                   description: 被删除的品牌数据
 *       404:
 *         description: 未找到该品牌数据
 *       500:
 *         description: 删除品牌数据失败
 */
router.delete("/deleteBrand/:id", userHandler.deleteBrandData_handler);

module.exports = router;
